<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	
<%@include file="/include/head.jsp"%>

<div id="cc" class="easyui-layout" style="width:100%;height:100%;">   
	<div data-options="region:'center',title:'送货单-<fmt:formatDate value="${vo.sendDate}" pattern="yyyy-MM-dd"/> 信息'" style="padding:5px;background:#eee;">
		<form id="editForm"   method="post" enctype="multipart/form-data" >
			<input name="id" type="hidden" value="${vo.id}">
			<input name="status" type="hidden" value="${vo.status}">
				<!-- 提交的时候存放子表订单明细信息 -->
				<input id="orderbData" name="orderbData" type="hidden" value="">
			<table cellpadding="0" cellspacing="1" class="formtable">
				<tr>
				<td align="right"><label class="Validform_label">送货日期:</label></td>
				<td class="value">
				<input class="easyui-datebox" type="text"  id="sendDate" name="sendDate"
				 data-options="required:true" value="<fmt:formatDate value="${vo.sendDate}" pattern="yyyy-MM-dd"/>" />
				</td>
				<td align="right"><label class="Validform_label">送货人:</label></td>
				<td class="value">
				<input class="easyui-textbox" type="text"  id="sender" name="sender"
				 data-options="required:true" value="${vo.sender}" />
				</td>
				</tr>
				<tr>
				<td align="right"><label class="Validform_label">备注:</label></td>
				<td class="value" colspan="3">
				<input class="easyui-textbox" type="text"  multiline=true id="remark" name="remark"
				 data-options="required:true,height:40,width:400" value="${vo.remark}" />
				</td>
				</tr>
			</table>
		</form>
		<div id="tt" class="easyui-tabs" style="width:100%;height:380px;"> 
		 	<div title="送货明细" data-options="closable:false" style="overflow:auto;">   
	        	<table id="dg_orderb"> </table>    
	     	</div>   
		</div>
	</div>
	<div data-options="region:'south'" style="height:35px;text-align: center;padding-top: 5px">
	 	<a id="btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="save()" >保存</a>  
	 	<a id="btncancel" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="closeDialog()">关闭</a>  
	 </div>
</div>
<script type="text/javascript">
var dialog = frameElement.dialog;
$(function() {
	$('#editForm').form({    
	    url:'saveOrUpdate.do', 
	    iframe:false,   
	    onSubmit: function(){ 
	    	//do your things on submint
	    },    
	    success:function(data){    
	    	data = JSON.parse(data);
	    	if(data.result == '1')
	    	{
	    		$.messager.alert("保存结果","保存成功",'info',function(){
	    			if($.isFunction(dialog.dialog('options').callback))
	    			{
	    				dialog.dialog('options').callback(data);
	    			}
	    			closeDialog();
		    	});	
	    	}
	    	else
	    	{
	    		$.messager.alert("保存结果","保存失败：" + data.message,'error',function(){
	    			
		    	});
	    	}
	    }    
	});
	
	    initEditableCurdDatagrid4Sub('orderb','dg_orderb',{
			title:null,
			pagination:false,
			model:'${vo.id}'==''?'add':'edit',
			height:'100%',
			url:'${ctx}/platform/orderb/listAllData.do',
			queryParams:{'deliveryId':'${vo.id}'},
			baseUrl:'${ctx}/platform/orderb/',
			btnCtl:'remove',
			fitColumns:false,
			remoteSort:false,
			loadFilter: function(data){
				return data;
			},
			columns:[[
				        	{field:'orderhId',title:'订单头ID',width:100,sortable:true,hidden:true},    
				        	{field:'extOrderNo',title:'外部订单编号',width:100,sortable:true},    
				        	{field:'productId',title:'产品ID',width:100,sortable:true,hidden:true},    
				        	{field:'productName',title:'产品名称',width:150,sortable:true},    
				        	{field:'productSpec',title:'产品规格',width:100,sortable:true,hidden:true},    
				        	{field:'unit',title:'单位',width:100,sortable:true,hidden:true},    
				        	{field:'productNum',title:'数量',width:40,sortable:true,formatter:formatInt},    
				        	{field:'unitPrice',title:'单价',width:50,sortable:true,formatter:formatDouble},    
				        	{field:'totalPrice',title:'总价',width:60,sortable:true,formatter:formatDouble},    
				        	{field:'recvId',title:'收货地址ID',width:100,sortable:true,hidden:true},   
				        	{field:'recvName',title:'收货单位',width:200,sortable:true},    
				        	{field:'recvAdd',title:'收货地址',width:200,sortable:true},    
				        	{field:'recvContactor',title:'联系人',width:60,sortable:true},    
				        	{field:'recvTel',title:'收货电话',width:180,sortable:true},    
				        	{field:'isPlanSend',title:'是否安排送货',width:100,sortable:true,hidden:true},    
				        	{field:'sendDate',title:'送货日期',width:100,sortable:true,hidden:true,formatter:formatDate},    
				        	{field:'sendWay',title:'送货方式',width:100,sortable:true,hidden:true},    
				        	{field:'deliveryman',title:'送货人',width:100,sortable:true,hidden:true},    
				        	{field:'isSigned',title:'是否签收',width:100,sortable:true,hidden:true},    
				        	{field:'signer',title:'签收人',width:100,sortable:true,hidden:true},    
				        	{field:'signDate',title:'签收日期',width:100,sortable:true,hidden:true,formatter:formatDate}    
				    ]] 
		},[{ 
			text: '添加', 
	        iconCls: 'icon-add', 
	        handler: function() { 
	        	var ids = "";
	        	var orderbData = $("#dg_orderb").edatagrid('getData');
	        	for(var i = 0; i< orderbData.total; i++)
	        	{
	        		 ids += "," + orderbData.rows[i].id;
	        	}
	        	if(ids.length>= 1)
	        		ids = ids.substring(1);
	        	SendableOrderbDialog('','',true,{exids:ids},function(data){
	        		for(var i =0; i < data.data.length; i++)
	        		{
	        			$('#dg_orderb').edatagrid('appendRow',data.data[i]);
	        		}
	        		
	        	})
	        } 
	    }, '-']);
	  
});

function save(){
	//验证表单
	if(!$("#editForm").form('validate'))
	{
		
		$.messager.alert("验证结果","表单验证失败",'error',function(){
    	});
		return;
	}
	
		//获取子表订单明细信息 ，并填充后提交
	var orderbData = $("#dg_orderb").edatagrid('getData');
	for(var i = 0; i< orderbData.total; i++)
	{
		 if(!$("#dg_orderb").edatagrid('validateRow',i))
		{
			 $.messager.alert("验证结果","第"+(i+1)+"行验证失败",'error',function(){
		    	});
				return;
		}
	}

		//保存表格
		$("#dg_orderb").edatagrid('saveRow');
	
	$("#orderbData").val(JSON.stringify(orderbData.rows));
	//提交表单
	$("#editForm").submit();  
}
function closeDialog()
{
	dialog.dialog("close");
}

</script>
